<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="60%">
    <el-form :model="form" :rules="rules" ref="form" label-width="80px">
      <el-row :gutter="4">
        <!-- <el-col :span="8"
          ><el-form-item label="类型" style="width: 100%">
            {{ row.type }}
          </el-form-item></el-col
        > -->
        <el-col :span="8"><el-form-item label="企业全称">
            {{ row.enterpriseName }}
          </el-form-item></el-col>
        <el-col :span="8"><el-form-item style="width: 100%" label="联系人">
            {{ row.contactName }}
          </el-form-item></el-col>
        <el-col :span="8"><el-form-item label="联系电话" style="width: 100%">
            {{ row.contactPhone }}
          </el-form-item></el-col>
        <!-- <el-col :span="8"
          ><el-form-item label="联系邮箱">
            {{ row.type }}
          </el-form-item></el-col
        > -->
        <el-col :span="8"><el-form-item style="width: 100%" label="地址">
            {{ row.sheng + row.shi + row.qu }}
          </el-form-item></el-col>
        <el-col :span="24"><el-form-item label="联系地址" style="width: 100%">
            {{ row.contactAddress }}
          </el-form-item></el-col>
        <el-col :span="24"><el-form-item label="营业执照">
            <el-image title="点击放大" style="width: 100%; height: 300px" :src="row.businessLicense"
              :preview-src-list="[row.businessLicense]">
            </el-image> </el-form-item></el-col>
        <el-col :span="24" v-if="isExamine"><el-form-item label="客户等级">
            <el-select v-model="form.vipLevel">
              <el-option v-for="item in vipLevelList" :key="item.vipLevel" :label="item.vipName"
                :value="item.vipLevel"></el-option>
            </el-select> </el-form-item></el-col>
        <el-col :span="24" v-if="isExamine"><el-form-item label="审核">
            <el-select v-model="form.checkStatus">
              <el-option label="通过" :value="3"></el-option>
              <el-option label="不通过" :value="2"></el-option>
            </el-select> </el-form-item></el-col>
        <el-col :span="24" v-if="form.checkStatus == '2'"><el-form-item label="备注" prop="checkRemark">
            <el-input :disabled="!isExamine" type="textarea" v-model="form.checkRemark"></el-input>
          </el-form-item></el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cance">取 消</el-button>
      <el-button type="primary" @click="determine">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { deepClone } from "@/utils";
export default {
  props: {
    getTableData: {
      type: Function,
    },
  },
  data() {
    return {
      row: {},
      vipLevelList: [],
      customerId: "",
      title: "查看",
      dialogFormVisible: false,
      isExamine: false,
      form: {
        vipLevel: "",
        checkStatus: 3,
        checkRemark: "",
      },
      rules: {
        checkRemark: [
          { validator: (rule, value, cb) => this.checkNotes(rule, value, cb) },
        ],
      },
    };
  },
  methods: {
    checkNotes(rule, value, cb) {
      if (!this.form.checkStatus) {
        cb("请说明不通过的理由");
      }
      cb();
    },
    determine() {
      if (!this.isExamine) {
        this.dialogFormVisible = false;
        return;
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$post("/system/customer/check", this.getParams()).then((res) => {
            if (res && res.code * 1 === 200) {
              this.$message({
                type: "success",
                message: "操作成功",
              });
              this.dialogFormVisible = false;
              this.getTableData();
            }
          });
        }
      });
    },
    getParams() {
      const params = deepClone(this.form);
      params.customerId = this.customerId;
      return params;
    },
    cance() {
      this.$refs.form.resetFields();
      this.dialogFormVisible = false;
    },
    getVipLevelList() {
      this.$get("/customer/vip/list").then((res) => {
        if (res && res.code * 1 === 200) {
          this.vipLevelList = res.rows;
          if (res.rows.length) {
            this.form.vipLevel = res.rows[0].vipLevel;
          }
        } else {
          this.vipLevelList = [];
        }
      });
    },
  },
  mounted() {
    this.getVipLevelList();
  },
};
</script>
